package org.longs.converter.parser;

import org.longs.bean.PalRGB;

import java.awt.*;

public class SeparateAlphaParser implements Parser {
    private int aByte;

    @Override
    public boolean judge(int flag) {
        aByte = flag;
        return aByte >> 5 == 1;
    }

    @Override
    public void analysis(Recorder recorder, BufferedColorListener result) {
        recorder.setFlag("SeparateAlpha");
        PalRGB color = recorder.getPalRGBs()[recorder.getBytes()[recorder.getOffsetUp()] & 0xFF];
        int alpha = aByte & 0x1F;
        alpha = (alpha << 3) | (alpha >> 2);
        result.result(new Color(color.getR(), color.getG(), color.getB(), alpha), recorder);
    }
}
